<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"
  />
  <meta name="format-detection" content="telephone=no, email=no, date=no, address=no" />
  <title>来加加</title>
</head>

<body>
  <header></header>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
  apiready = function () {
    var currentPath = 'home'
    var header = $api.dom('header') // 获取 header 标签元素1
    api.openFrame({
      name: 'app',
      // url: 'http://h5.jmgxmt1010sc.com/?isApp=true',
      // url: 'http://lfmall-h5.anli.zovikj.cn/?isApp=true',
      url: 'http://b2b2c-h5.anli.zovikj.cn/home?isApp=true',
      // url: 'http://192.168.1.2:8081/?isApp=true&isDebug=true',
      bounces: false,
      scrollEnabled: api.systemType === 'ios',
      allowEdit: true,
      rect: {
        // 推荐使用Margin布局，用于适配屏幕的动态变化
        w: 'auto', // main页面的宽度 自适应屏幕宽度
      },
      animation: {
        type: 'none',
        subType: 'none',
        duration: 0,
      },
    })
    // 获取路由名称
    api.addEventListener(
      {
        name: 'current',
      },
      function (ret, err) {
        if (ret && ret.value) {
          var value = ret.value
          currentPath = value.name
        }
      }
    )
    // 刷新页面
    api.addEventListener(
      {
        name: 'reload',
      },
      function (ret, err) {
        if (ret && ret.value) {
          var value = ret.value
          if (value.type === 'reload') {
            api.clearCache()
            var js = 'window.location.reload()'
            api.execScript({
              name: 'main',
              frameName: 'app',
              script: js,
            })
          }
        }
      }
    )
    api.addEventListener(
      {
        name: 'keyback',
      },
      function (ret, err) {
        // getPathname();
        api.sendEvent({ name: 'my_keyback' })
      }
    )
    // 系统返回按键处理
    var mkeyTime = new Date().getTime()
    api.addEventListener(
      {
        name: 'my_keyback',
      },
      function (ret, err) {
        if (currentPath === 'home') {
          if (new Date().getTime() - mkeyTime > 2000) {
            mkeyTime = new Date().getTime()
            api.toast({
              msg: '再按一次退出',
              duration: 2000,
              location: 'bottom',
            })
          } else {
            setTimeout(function () {
              api.closeWidget({
                silent: true,
              })
            }, 500)
          }
        } else {
          var js = 'window.history.go(-1)'
          api.execScript({
            ///在指定页面中执行srcipt中脚本
            name: 'main', ///打开外部网页的Win名
            frameName: 'app', ///呈现外部网页的frame名
            script: js,
          })
        }
      }
    )
  }
</script>

</html>